package io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @description: io2
 * @author: rock
 * @create:
 **/
public class Io2 {
    public static void main(String[] args) {
        test2();
    }



    private  static void test2(){
        String s1 = "D:/demo/lalala.txt";
        String s2 = "D:/demo/lalala-s.txt";
        try(InputStreamReader inputStreamReader=
                    new InputStreamReader(new FileInputStream(s1),"UTF-8");
            OutputStreamWriter outputStreamWriter =
                    new OutputStreamWriter(new FileOutputStream(s2,true),"UTF-8");) {


            //读取文件内容
            char[] chars = new char[1024];
            int len = -1;
            System.out.println("读取的内容：");
            do {
                len = inputStreamReader.read(chars, 0, 1024);
                if(len>0){
                    String str = new String(chars,0,len);
                    System.out.println(str);
                    outputStreamWriter.write(chars,0,len);



                }

            } while (len > 0);

            //清空和刷新写出缓存去
            inputStreamReader.close();
            outputStreamWriter.close();



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
